package stud.aistar.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import stud.aistar.entity.Treatment;
import stud.aistar.mapper.TreatmentMapper;
import stud.aistar.service.ITreatmentService;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * *
 *
 * @ClassName :wangyu
 * @Description
 * @Author
 * @Date2019/9/28 19:32
 * @Version V1.0
 */
@Service
    @Transactional
public class TreatmentServiceImpl implements ITreatmentService {

    @Autowired
    private TreatmentMapper mapper;

    @Override
    public PageInfo<Treatment> findPage(Integer docId, Map<String,String> paramMap) {

        Integer pageNum = Integer.valueOf(paramMap.get("page"));

        Integer pageSize = Integer.valueOf(paramMap.get("limit"));

        PageHelper.startPage(pageNum,pageSize);

        List<Treatment> list = mapper.findAll(docId);

        PageInfo<Treatment> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public List<Treatment> findAll(Integer dId) {

        List<Treatment> list = mapper.findAll(dId);
        return list;
    }

    @Override
    public Treatment findByName(String patName) {

        Treatment treatment = mapper.findByName(patName);
        return treatment;

    }

    @Override
    public void updById(Treatment treatment, Integer id) {
        mapper.updById(treatment,id);
    }

    @Override
    public void delById(Integer id) {
        mapper.delById(id);
    }

    @Override
    public void insName(Treatment treatment) {
        mapper.insName(treatment);
    }

    @Override
    public int FindTreatmentCount() {

        Integer count = mapper.FindTreatmentCount();

        return count;
    }

    @Override
    public Treatment findByPatId(Integer patId) {

        Treatment treatment = mapper.findByPatId(patId);

        return treatment;
    }

    @Override
    public List<Treatment> findByPatName(String patName,Integer docId) {

        List<Treatment> list = mapper.findByPatName(patName,docId);

        return list;
    }

    @Override
    public PageInfo<Treatment> findPatNamePage(Integer docId, String patName, Map<String, String> paramMap) {

        Integer pageNum = Integer.valueOf(paramMap.get("page"));

        Integer pageSize = Integer.valueOf(paramMap.get("limit"));

        PageHelper.startPage(pageNum,pageSize);

        List<Treatment> treatments = mapper.findByPatName(patName,docId);

        PageInfo<Treatment> pageInfo = new PageInfo<>(treatments);

        return pageInfo;
    }
}
